from selenium import webdriver
from selenium.webdriver.common.by import By
import datetime
import time
buy_time = '2023-12-17 23:48:00'
driver = webdriver.Edge()
# driver = webdriver.Chrome()

# driver.maximize_window()


#进入京东首页
driver.get("https://www.jd.com/")
time.sleep(10)
#点击登录按钮114.0.5735.134
driver.find_element(By.CLASS_NAME,"link-login").click()
#点击账号登陆
# driver.find_element(by=By.PARTIAL_LINK_TEXT,value="账户登录").click()
driver.find_element(by=By.PARTIAL_LINK_TEXT,value="扫码登录").click()
# #输入账号密码
# uName = driver.find_element(by=By.ID,value="loginname")
# uName.send_keys("17691230520")
# passWord = driver.find_element(by=By.ID,value="nloginpwd")
# passWord.send_keys("Tianalong2022..")
# driver.find_element(by=By.ID,value="loginsubmit").click()
time.sleep(15)
#进入购物车页面
driver.get('https://cart.jd.com/cart_index')
time.sleep(3)
#选择全选按钮
driver.find_element(by=By.CLASS_NAME,value="jdcheckbox").click()
time.sleep(1)
while True:
    now  = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")
    if now >= buy_time  :
        print(now)
        try:
            driver.find_element(by=By.CLASS_NAME, value="common-submit-btn").click()
        except:
            print('异常了')
            time.sleep(10)
    else:
        print(now)
        time.sleep(0.1)

    if now > buy_time :
        print("抢购已经结束！！！")
        print(now)
        try:
            driver.find_element(by=By.ID, value="order-submit").click()
        except:
            print('提交订单异常了！！')
            time.sleep(10)
